package com.mowh.multithreading.immutable;

/**
 * @author mowh1gd
 * @create 2023/11/9 15:37
 */
public final class Person { //扮演Immutable角色，类中没有改变字段的方法，即setter方法。getter方法都是线程安全的可并发的。无需synchronized声明方法。注意也有特例会修改字段的值。
    private final String name; // 类图的{frozen}对应final修饰符
    private final String address;

    public Person(String name, String address) {
        this.name = name;
        this.address = address;
    }

    public String getName() { //类图的{concurrent}
        return name;
    }

    public String getAddress() { //类图的{concurrent}
        return address;
    }

    @Override
    public String toString() {
        return "[ Person: name = " + name + ", address = " + address + " ]";
    }
}
